package com.ungs.form;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import com.ungs.utils.Constantes;

public class AcercaDeForm extends JDialog {
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private ImageIcon imagenLogo;
	private JLabel lbImagen;

	public AcercaDeForm(JFrame parent) {
		super(parent, true);
		imagenLogo = new ImageIcon(Constantes.LOGO_CHICO);
		initForm();
	}

	private void initForm() {
		setTitle("Acerca de");
		setBounds(100, 100, 400, 425);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JPanel panel = new JPanel();
			panel.setBorder(new TitledBorder(null, "Imprenta CMYK",
					TitledBorder.LEADING, TitledBorder.TOP, null, null));
			panel.setBounds(10, 11, 511, 158);
			contentPanel.add(panel);
			panel.setLayout(null);
			{
				JPanel panelLogoCMYK = new JPanel();
				panelLogoCMYK.setBorder(new LineBorder(new Color(0, 0, 0)));
				panelLogoCMYK.setBounds(10, 22, 192, 119);
				panel.add(panelLogoCMYK);
				panelLogoCMYK.setLayout(null);
				{
					lbImagen = new JLabel(imagenLogo);
					lbImagen.setBounds(0, 0, 192, 119);
					panelLogoCMYK.add(lbImagen);
				}
			}
			{
				JPanel panelInfo = new JPanel();
				panelInfo.setBounds(209, 22, 138, 125);
				panel.add(panelInfo);
				panelInfo.setLayout(null);
			}
		}
		{
			JPanel panelLicencia = new JPanel();
			panelLicencia.setBorder(new TitledBorder(new LineBorder(new Color(
					0, 0, 0)), " Informacion ", TitledBorder.LEADING,
					TitledBorder.TOP, null, new Color(0, 0, 0)));
			panelLicencia.setBounds(20, 180, 341, 173);
			contentPanel.add(panelLicencia);
			panelLicencia.setLayout(null);
			{
				JLabel lblUrl = new JLabel("URL:");
				lblUrl.setFont(new Font("Tahoma", Font.BOLD, 11));
				lblUrl.setBounds(10, 27, 38, 14);
				panelLicencia.add(lblUrl);
			}
			{
				final JLabel lbEnlaceRepo = new JLabel(Constantes.ENLACE_REPO);
				lbEnlaceRepo.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						// Abre la ruta del enlace
						Runtime aplicacion = Runtime.getRuntime();
						try {
							aplicacion.exec(Constantes.ABRIR_REPO);
						} catch (Exception ex) {
						}
					}

					@Override
					public void mouseEntered(MouseEvent e) {
						// Evento cuando se pasa el mouse
						lbEnlaceRepo.setCursor(new Cursor(Cursor.HAND_CURSOR));
					}
				});
				lbEnlaceRepo.setBounds(53, 27, 211, 14);
				panelLicencia.add(lbEnlaceRepo);
			}
			{
				JTextPane txtInfo = new JTextPane();
				txtInfo.setEditable(false);
				txtInfo.setFont(new Font("Tahoma", Font.BOLD, 11));
				txtInfo.setBackground(SystemColor.inactiveCaptionBorder);
				txtInfo.setBounds(10, 52, 244, 82);
				txtInfo.setText(Constantes.AUTORES);
				panelLicencia.add(txtInfo);
			}
			{
				JLabel lbVersion = new JLabel(Constantes.VERSION);
				lbVersion.setFont(new Font("Tahoma", Font.BOLD, 11));
				lbVersion.setBounds(10, 145, 251, 14);
				panelLicencia.add(lbVersion);
			}
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("Cerrar");
				okButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						aceptar();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
	}

	private void aceptar() {
		this.setVisible(false);
		this.dispose();
	}
}
